package com.nowcoder.community.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/*
* 面向切面编程示例
* */
//@Component
@Aspect
@Slf4j
public class AlphaAspect {

    @Pointcut("execution(* com.nowcoder.community.service.*.*(..))")
    public void pointcut(){}

    @Before("pointcut()")
    public void before(){
        log.debug("before");
    }

    @After("pointcut()")
    public void after(){
        log.debug("after");
    }

    @AfterThrowing("pointcut()")
    public void afterThrowing(){
        log.debug("after throwing");
    }

    @AfterReturning("pointcut()")
    public void afterReturning(){
        log.debug("after returning");
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinpoint) throws Throwable {
        log.debug("round before");
        Object proceed = joinpoint.proceed();
        log.debug("round after");
        return proceed;
    }
}
